﻿using Microsoft.SharePoint;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindStyle.SPEntity
{
    public static class Utilities
    {
        public static IEnumerable<SPListItem> AsEnumerable(this SPListItemCollection items)
        {
            return items.Cast<SPListItem>();
        }

        public static IEnumerable<T> Convert<T>(this IEnumerable<SPListItem> items, SPRegionalSettings regionalSettings = null) where T: Entity, new()
        {
            if (items != null)
            {
                foreach (var item in items)
                {
                    var entity = new T();
                    entity.Read(item, regionalSettings);
                    yield return entity;
                }
            }
        }
    }
}
